package com.lin.manager.order.service.impl;

import com.lin.manager.common.enums.PayEnum;
import com.lin.manager.common.ex.BizException;
import com.lin.manager.order.model.PayVo;
import com.lin.manager.order.service.OrderPayService;
import com.lin.manager.pay.model.dto.PayDto;
import com.lin.manager.pay.service.PayService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Optional;

/**
 * @作者: 林江
 * @创建时间: 2024/4/21
 * @功能:
 */
@Service
public class OrderPayServiceImpl implements OrderPayService {
    @Autowired
    PayService payService;

    @Override
    public void orderPay(Integer type, PayVo vo) {
        Optional<PayEnum> optional = Arrays.stream(PayEnum.values()).filter(item -> item.getType() == type.intValue()).findFirst();
        if (optional.isPresent()) {
            PayDto dto = new PayDto();
            BeanUtils.copyProperties(vo, dto);
            dto.setType(optional.get().getPay());
            payService.pay(dto);
        } else {
            throw new BizException("系统未开放此种支付方式");
        }
    }
}
